﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BusinessHandler
{
    public class AdvertisementItemController : AdvertisementDataContext
    {
        private static AdvertisementItemController instance;
        public static AdvertisementItemController Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new AdvertisementItemController();
                }
                return instance;
            }
            set
            {
                instance = value;
            }
        }
        public int Insert(AdvertisementItem item)
        {
            AdvertisementDataContext dtc = new AdvertisementDataContext();
            try
            {
                dtc.AdvertisementItems.InsertOnSubmit(item);
                dtc.SubmitChanges();
                return 1;
            }
            catch
            {
                return 0;
            }
        }
        public AdvertisementItem FindItemByID(int id)
        {
            AdvertisementDataContext dataContext = new AdvertisementDataContext();
            AdvertisementItem item = (from o in dataContext.AdvertisementItems
                                      where o.Id == id
                                      select o).SingleOrDefault();
            return item;
        }
    }
}